package com.java.study.modules.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.java.study.DTO.StudentDTO;
import com.java.study.entity.StudentPO;
import com.java.study.modules.mapper.IStudentMapper;
import com.java.study.modules.service.IStudentService;
import com.java.study.utils.ToolUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * ClassName:IStudentServiceImpl
 * Description:
 *
 * @Date:2022/8/29 13:52
 * @Author:chenruifeng
 */
@Service
public class IStudentServiceImpl implements IStudentService {
    @Autowired
    private IStudentMapper iStudentMapper;

    @Override
    public StudentPO findByNames(String name) {
        return iStudentMapper.findByNames(name);
    }

    @Override
    public void batchInsert(StudentDTO studentDTO) {
        List<StudentDTO> studentDTOList = new ArrayList<>();
        for (int i = 1; i <= studentDTO.getCount(); i++) {
            UUID uuid = UUID.randomUUID();
            String id = uuid.toString().replaceAll("-", "");
            //随机字符串
            String name = ToolUtils.randomString();
            StudentDTO dto = new StudentDTO();
            dto.setStuid(id);
            dto.setStuname(name);
            dto.setStusex(studentDTO.getStusex());
            dto.setStuaddr(studentDTO.getStuaddr());
            dto.setStuage(studentDTO.getStuage());
            dto.setColid(studentDTO.getColid());
            studentDTOList.add(dto);
        }
        iStudentMapper.batchInsert(studentDTOList);
    }
}
